﻿using System;

namespace Tatibah
{
    /// <summary>
    /// Base class for all items that require MultipleStrings Formatting. These items are a Paragraph, a Run and a Style.
    /// </summary>
    public class BaseTextFormatting 
    {
        /// <summary>
        /// Common Ascii name of a font. e.g.Ariel
        /// </summary>
        public string FontName { get; set; }
        private double fontSize = 0.0; // See Property FontSize

        /// <summary>
        /// Font colour as hex string RRGGBB
        /// </summary>
        public string FontColour = "";

        /// <summary>
        /// Determines if the MultipleStrings will be Bold or not
        /// </summary>
        public bool? Bold  {get; set;}

        /// <summary>
        ///  Determines if the MultipleStrings will be in Italics or not
        /// </summary>
        public bool? Italics {get; set;}

        /// <summary>
        ///  Determines if the MultipleStrings will be Hidden or not
        /// </summary>
        public bool? Hidden {get; set;}

        private bool? underLine {get; set;}
        /// <summary>
        /// Sets the Style of the Underlining
        /// </summary>
        public DocumentFormat.OpenXml.Wordprocessing.UnderlineValues UnderLineStyle {get; set;}

        /// <summary>
        /// Underline colour as hex string RRGGBB
        /// </summary>
        public string UnderLineColour = "";

        // Effects 
        // Private Effects are mutually exclusive with some other, see the appropriate Properties
        private bool? strikeThrough = false;
        private bool? doubleStrikeThrough = false;

        /// <summary>
        /// Internal use
        /// </summary>
        public BaseTextFormatting()
        {
            UnderLineStyle = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.None;
        }
        #region P R O P E R T I E S

        /// <summary>
        /// If true MultipleStrings is underlined with a default single underline, otherwise no underlining
        /// </summary>
        public bool? UnderLine
        {
            get { return underLine; }
            set
            {
                if (value != null)
                {
                    if (value == true)
                    {
                        if (UnderLineStyle == DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.None)
                            UnderLineStyle = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single;
                        if (UnderLineColour == "")
                            UnderLineColour = "000000";  // Color.Black;
                        underLine = true;
                    }
                    else
                    {
                        UnderLineStyle = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.None;
                        UnderLineColour = "";
                        underLine = false;
                    }
                }
                else
                    underLine = null;
            }
        }

        /// <summary>
        /// MultipleStrings is struck through, mutually exclusive to doubleStrikeThrough
        /// </summary>
        private bool? StrikeThrough
        {
            get { return strikeThrough; }
            set
            {
                if (value != null && value == true)
                {
                    doubleStrikeThrough = null; // Mutually exclusive
                    strikeThrough = value;
                }
                else
                    strikeThrough = value;
            }
        }

        /// <summary>
        /// MultipleStrings is doubleStrikeThrough through, mutually exclusive to StrikeThrough
        /// </summary>
        private bool? DoubleStrikeThrough
        {
            get { return doubleStrikeThrough; }
            set
            {
                if (value != null && value == true)
                {
                    strikeThrough = null; // Mutually exclusive
                    doubleStrikeThrough = value;
                }
                else
                    doubleStrikeThrough = value;
            }
        }

        /// <summary>
        /// Fonst size must be in increments of a half e.g. 8, or 11.5
        /// </summary>
        public double FontSize
        {
            get { return fontSize; }
            set
            {
                // Font sizes can either be whole numbers or whole numbers plus a half
                if (value * 2 == Math.Floor(value * 2))
                    fontSize = value;
                else
                    throw new Exception("Font size must be in increments of a half. e.g. 8, or 11.5");

            }
        }

        #endregion P R O P E R T I E S
    }
}
